<template>
  <el-form :inline="true" :model="formInline" class="demo-form-inline">
    <el-form-item label="单据编码">
      <el-input v-model="formInline.DocumentNo" placeholder="请输入单据编码" clearable />
    </el-form-item>
    <el-form-item label="供应商名称">
      <el-input v-model="formInline.Vendor" placeholder="请输入供应商名称" clearable />
    </el-form-item>
    <el-form-item label="发票号码">
      <el-input v-model="formInline.InvoiceNumber" placeholder="请输入发票号码" clearable />
    </el-form-item>
    <!-- <el-form-item label="开始日期">
          <el-input v-model="" placeholder="物料名称" clearable />
      </el-form-item>
      <el-form-item label="结束日期">
          <el-input v-model="" placeholder="物料名称" clearable />
      </el-form-item> -->
    <el-form-item>
      <el-button type="primary" @click=""><svg t="1734662227937" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2540" width="18" height="18"><path d="M966.4 924.8l-230.4-227.2c60.8-67.2 96-156.8 96-256 0-217.6-176-390.4-390.4-390.4-217.6 0-390.4 176-390.4 390.4 0 217.6 176 390.4 390.4 390.4 99.2 0 188.8-35.2 256-96l230.4 227.2c9.6 9.6 28.8 9.6 38.4 0C979.2 950.4 979.2 934.4 966.4 924.8zM102.4 441.6c0-185.6 150.4-339.2 339.2-339.2s339.2 150.4 339.2 339.2c0 89.6-35.2 172.8-92.8 233.6-3.2 0-3.2 3.2-6.4 3.2-3.2 3.2-3.2 3.2-3.2 6.4-60.8 57.6-144 92.8-233.6 92.8C256 780.8 102.4 627.2 102.4 441.6z" p-id="2541" fill="#ffffff"></path></svg>搜索</el-button>
    </el-form-item>
  </el-form>
  <el-button
    
    type="primary"
    size="mini"
    @click=""
  ><svg t="1734679536993" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2506" width="18" height="18"><path d="M800 192H640c0-70.4-57.6-128-128-128s-128 57.6-128 128H224c-17.6 0-32 14.4-32 32v704c0 17.6 14.4 32 32 32h576c17.6 0 32-14.4 32-32V224c0-17.6-14.4-32-32-32z m-288-32c17.6 0 32 14.4 32 32s-14.4 32-32 32-32-14.4-32-32 14.4-32 32-32z m64 608H320v-64h256v64z m128-128H320v-64h384v64z m0-128H320v-64h384v64z" p-id="2507" fill="#e6e6e6"></path></svg>单据</el-button>
  <el-button type="primary" size="mini" @click=""
    ><el-icon><Grid /></el-icon>&emsp;查询所有</el-button
  >
  <el-button
    style="background-color: #7acefe; border-color: #0ea3f7; color: #0ea3f7"
    size="mini"
    @click="router.push('/PurchaseInvoices/PurchaseInvoicesAddView')"
    ><el-icon style="color: #0ea3f7; border: 1px"><Plus /></el-icon
    >&emsp;新增</el-button
  >
  <el-button
    style="background-color: #f9ea83; border-color: #e2c50c; color: #e2c50c"
    type="warning"
    size="mini"
    @click=""
  >
    <el-icon><Download /></el-icon>导出</el-button>


  <!-- <el-empty description="暂无数据" v-show="" /> -->

     <el-table
    :data="purchaseInvoiceReadData"
    stripe
    style="width: 100%"
    v-show="purchaseInvoiceReadData.length != 0"
  >
    <el-table-column prop="purchaseInvoiceId" label="序号" />
    <el-table-column prop="documentNo" label="单据编号" >
      <template #default="scope">
        <el-link type="primary" @click="router.push('/PurchaseInvoices/PurchaseInvoicesDetailView?documentNo='+scope.row.documentNo)">{{
          scope.row.documentNo
        }}</el-link>
      </template>
    </el-table-column>
    <el-table-column prop="documentDate" label="单据日期" >
      <template #default="scope">
        {{ scope.row.documentDate == null? "" : scope.row.documentDate.substring(0, 10) }}    
      </template>
    </el-table-column>
    <el-table-column prop="documentStatus" label="单据状态" >
      <template #default="scope">
         <span style="color:yellow;">{{ scope.row.documentStatus }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="businessType" label="业务类型" />
    <el-table-column prop="vendor" label="厂家名称" />
    <el-table-column prop="invoiceNumber" label="发票号码" />
    <el-table-column prop="invoiceAmount" label="发票金额" />
    <el-table-column prop="taxRate" label="税率" />
    <el-table-column prop="amountOfTax" label="税额" />
    <el-table-column prop="invoiceStatus" label="财务状态" />
    <el-table-column prop="documentDate" label="单据日期" >
      <template #default="scope">
        {{ scope.row.documentDate == null? "" : scope.row.documentDate.substring(0, 10) }}
      </template>
    </el-table-column>
  </el-table>

  <div>
    <tr>
      <td>
        <el-pagination
          v-model:current-page="formInline.PageIndex"
          v-model:page-size="formInline.PageSize"
          :page-sizes="[10, 20, 30, 40, 50]"
          :background="true"
          layout="total, slot, prev, pager, next"
          :total="formInline.totalCount"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </td>
      <td>
        <el-pagination
          v-model:current-page="formInline.PageIndex"
          v-model:page-size="formInline.PageSize"
          :page-sizes="[10, 20, 30, 40, 50]"
          :background="true"
          layout="slot, sizes, jumper"
          :total="formInline.totalCount"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </td>
    </tr>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRoute } from 'vue-router';
import axios from 'axios';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue';
import type { TabsPaneContext } from 'element-plus';
const router = useRouter();
const route = useRoute();
const formLabelWidth = '140px';
const apiurls = import.meta.env.VITE_APP_API_URL_BasicInformationCommon;//5176
const bpiurls = import.meta.env.VITE_APP_API_URL_BasicInformationWrite;//5013
const cpiurls = import.meta.env.VITE_APP_API_URL_RBACCommon;//5214
const dpiurls = import.meta.env.VITE_APP_API_URL_RBACWrite;//5268
const epiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const fpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementWrite;//5020
onMounted(() => {
  getPurchaseInvoiceReadQuery();
});

const formInline = reactive({
  DocumentNo: '',
  Vendor: '',
  InvoiceNumber: '',
  PageIndex: 1,
  PageSize: 10,
  totalCount: 0,
  totalPage: 0
});
const purchaseInvoiceReadData = ref([]);
const getPurchaseInvoiceReadQuery = () => {
  axios
    .get(epiurls+'/api/SalesOrder/PurchaseInvoiceReadQuery',{
      params:{
        DocumentNo:formInline.DocumentNo,
        Vendor: formInline.Vendor,
        InvoiceNumber: formInline.InvoiceNumber,
        PageIndex: formInline.PageIndex,
        PageSize: formInline.PageSize,
      }
    })
    .then((res) => {
      console.log(res.data);
      purchaseInvoiceReadData.value = res.data.data.list;
      formInline.totalCount  = res.data.data.totalCount;
      formInline.totalPage = res.data.data.totalPage;
    })
    .catch((err) => {
      console.log(err);
    });
};

//分页
const handleSizeChange = (val: number) => {
  formInline.PageSize = val;
  getPurchaseInvoiceReadQuery();
};
const handleCurrentChange = (val: number) => {
  formInline.PageIndex = val;
  getPurchaseInvoiceReadQuery();
};
const detail = (documentNo: any) => {
  router.push({
    path: '/PurchaseInvoices/PurchaseInvoicesDetail',
    query: {
      documentNo: documentNo
    }
  })
}
</script>

<style>
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
</style>
